#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	freopen("bishop.in","r",stdin);
	freopen("bishop.out","w",stdout);
	int n,m,flg=0;
	cin>>n>>m;
	vector<pair<int,int>>ans;
	ans.reserve(n+m);
	vector<bool>va(n+m),vb(n+m);
	if(n>m)swap(n,m),flg=1;
	const auto ins=[&](const int&x,const int&y){
		if(!va[x+y]&&!vb[x-y+m])va[x+y]=vb[x-y+m]=1,ans.emplace_back(x,y);
	};
	for(int i=0;i<n;++i)ins(i,0);
	for(int i=0;i<n;++i)ins(i,m-1);
	for(int i=0;i<m;++i)ins((n-1)/2,i),ins(n/2,i);
	cout<<ans.size()<<'\n';
	for(auto [x,y]:ans)
		if(flg)cout<<y+1<<' '<<x+1<<'\n';
		else cout<<x+1<<' '<<y+1<<'\n';
	return 0;
}
/*

*/